home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261exe.zip / gs_lev2.ps < prev    next >
Text File  |  1993-05-28  |  11KB  |  391 lines

  1. %    Copyright (C) 1990, 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Ghostscript.
  4. %
  5. % Ghostscript is distributed in the hope that it will be useful, but
  6. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. % to anyone for the consequences of using it or for whether it serves any
  8. % particular purpose or works at all, unless he says so in writing.  Refer
  9. % to the Ghostscript General Public License for full details.
  10. %
  11. % Everyone is granted permission to copy, modify and redistribute
  12. % Ghostscript, but only under the conditions described in the Ghostscript
  13. % General Public License.  A copy of this license is supposed to have been
  14. % given to you along with Ghostscript so you can know your rights and
  15. % responsibilities.  It should be in a file named COPYING.  Among other
  16. % things, the copyright notice and this notice must be preserved on all
  17. % copies.
  18.  
  19. % Initialization file for Level 2 functions.
  20. % When this is run, systemdict is still writable,
  21. % but everything defined here goes into level2dict.
  22.  
  23. level2dict begin
  24.  
  25. % ------ Miscellaneous ------ %
  26.  
  27. (<<) cvn /mark load def
  28. (>>) cvn /.dicttomark load odef
  29. /currentsystemparams { mark .currentsystemparams .dicttomark } odef
  30. /currentuserparams { mark .currentuserparams .dicttomark } odef
  31. /deviceinfo { currentdevice getdeviceprops .dicttomark } odef
  32. /globaldict currentdict /shareddict .knownget not { 20 dict } if def
  33. /realtime /usertime load def
  34.  
  35. % ------ Painting ------ %
  36.  
  37. % A straightforward definition of execform that doesn't actually
  38. % do any caching.
  39. /execform
  40.  { dup /Implementation known not
  41.     { dup /FormType get 1 ne { /rangecheck signalerror } if
  42.       dup /Implementation null put readonly
  43.     } if
  44.    gsave dup /Matrix get concat
  45.    dup /BBox get aload pop
  46.    exch 3 index sub exch 2 index sub rectclip
  47.    dup /PaintProc get exec
  48.    grestore
  49.  } odef
  50.  
  51. /setpattern
  52.  { currentcolorspace 0 get /Pattern ne
  53.     { [ /Pattern currentcolorspace ] setcolorspace
  54.     } if
  55.    setcolor
  56.  } odef
  57.  
  58. % ------ Virtual memory ------ %
  59.  
  60. /currentglobal /currentshared load def
  61. /gcheck /scheck load def
  62. /globaldict /shareddict load def
  63. /setglobal /setshared load def
  64.  
  65. % ------ Resources ------ %
  66.  
  67. % Currently, we don't implement resource unloading (there wouldn't be
  68. % much value to it without garbage collection) or global/local
  69. % instance sets (since we don't have a global/local memory distinction.)
  70.  
  71. % Note that the dictionary that defines a resource category is stored
  72. % in global memory.  The PostScript manual says that each category must
  73. % manage global and local instances separately.  However, objects in
  74. % global memory can't reference objects in local memory.  This means
  75. % that the resource category dictionary, which would otherwise be the
  76. % obvious place to keep track of the instances, can't be used to keep
  77. % track of local instances.  Instead, there must be a parallel
  78. % structure in local memory for each resource category.  Needless to
  79. % say, we haven't implemented this yet.
  80.  
  81. % We keep track of instances in another entry in the resource dictionary,
  82. % called Instances.  For categories with implicit instances,
  83. % the values in Instances are the same as the keys; for other categories,
  84. % the values are [instance status size].
  85.  
  86. % Define the Category category, except for most of the procedures.
  87. % The dictionary we're about to create will become the Category
  88. % category definition dictionary.
  89.  
  90. 10 dict begin
  91. /Category /Category def
  92. /.CheckResource
  93.     { true        % dup gcheck currentglobal and
  94.        { /DefineResource /FindResource /ResourceForAll /ResourceStatus
  95.          /UndefineResource }
  96.        { 2 index exch known and }
  97.       forall exch pop
  98.     } bind def
  99. /DefineResource
  100.     { dup .CheckResource
  101.        { dup /Category 3 index put
  102.          dup [ exch 0 -1 ] exch
  103.          Instances 4 2 roll put
  104.        }
  105.        { /typecheck signalerror
  106.        }
  107.       ifelse
  108.     } bind def
  109. /FindResource        % (redefined below)
  110.     { Instances exch get 0 get
  111.     } bind def
  112. /Instances 25 dict def
  113. /InstanceType /dicttype def
  114.  
  115. Instances /Category [currentdict 0 -1] put
  116. Instances end begin    % so we can name the Category definition
  117.  
  118. % Define the resource operators.  I don't see how we can possibly restore
  119. % the stacks after an error, since the procedure may have popped and
  120. % pushed elements arbitrarily....
  121.  
  122. mark
  123. /defineresource
  124.     { /Category findresource dup begin
  125.       /InstanceType known
  126.        { dup type InstanceType ne
  127.          { dup type /packedarraytype eq InstanceType /arraytype eq and
  128.             not { /typecheck signalerror } if } if } if
  129.       /DefineResource load stopped end { stop } if
  130.     }
  131. /findresource
  132.     { dup /Category eq
  133.        { pop //Category 0 get } { /Category findresource } ifelse
  134.       begin
  135.       /FindResource load stopped end { stop } if
  136.     }
  137. /resourceforall
  138.     { /Category findresource begin
  139.       /ResourceForAll load stopped end { stop } if
  140.     }
  141. /resourcestatus
  142.     { /Category findresource begin
  143.       /ResourceStatus load stopped end { stop } if
  144.     }
  145. /undefineresource
  146.     { /Category findresource begin
  147.       /UndefineResource load stopped end { stop } if
  148.     }
  149. end        % Instances
  150. counttomark 2 idiv { bind odef } repeat pop
  151.  
  152. % Define the Generic category.
  153.  
  154. /Generic mark
  155.  
  156. /Instances 0 dict
  157. /.CheckResource        % not a standard entry
  158.     { pop true
  159.     } bind
  160. /DefineResource
  161.     { dup .CheckResource
  162.        { { readonly } stopped pop
  163.          dup [ exch 0 -1 ] exch
  164.          Instances 4 2 roll .growput
  165.        }
  166.        { /typecheck signalerror
  167.        }
  168.       ifelse
  169.     } bind
  170. /FindResource
  171.     { dup ResourceStatus
  172.        { pop 1 gt        % not in VM
  173.           { dup vmstatus pop exch pop exch
  174.             .LoadResource
  175.         vmstatus pop exch pop exch sub
  176.         Instances 2 index get
  177.         dup 1 1 put
  178.         2 3 -1 roll put
  179.           }
  180.          if
  181.          Instances exch get 0 get
  182.        }
  183.        { /undefinedresource signalerror
  184.        }
  185.       ifelse
  186.     } bind
  187. /.LoadResource        % not a standard entry; may fail
  188.     { .ResourceFile run
  189.     } bind
  190. /.ResourceFile        % not a standard entry; may fail
  191.     { currentdict /ResourceFileName get 100 string exch exec
  192.       findlibfile { exch pop } { (r) file } ifelse    % let the error happen
  193.     } bind
  194. /.ResourceFileDict    % not a standard entry
  195.     0 dict
  196. /ResourceFileName    % leave a slot
  197.     { exch dup .ResourceFileDict exch .knownget
  198.        { exch pop exch copy }
  199.        { exch pop /undefinedresource signalerror }
  200.       ifelse
  201.     } bind
  202. /ResourceForAll
  203.     { % We construct a new procedure so we don't have to use
  204.       % static resources to hold the iteration state.
  205.       3 packedarray        % template, proc, scratch
  206.       { exch pop    % stack contains: key, {template, proc, scratch}
  207.         2 copy 0 get .stringmatch
  208.          { 1 index type dup /stringtype eq exch /nametype eq or
  209.             { 2 copy 2 get cvs
  210.           exch 1 get 3 -1 roll pop
  211.         }
  212.         { 1 get
  213.         }
  214.            ifelse exec
  215.          }
  216.          { pop pop
  217.          }
  218.         ifelse
  219.       } /exec cvx 3 packedarray cvx
  220.       Instances exch forall
  221.     } bind
  222. /ResourceStatus
  223.     { dup Instances exch .knownget
  224.        { exch pop dup 1 get exch 2 get true }
  225.        { mark exch { .ResourceFile } stopped
  226.           { cleartomark false } { closefile cleartomark 2 -1 true }
  227.          ifelse
  228.        }
  229.       ifelse
  230.     } bind
  231. /UndefineResource
  232.     { dup Instances exch .knownget
  233.        { dup 1 get 1 ge
  234.           { dup 0 null put 1 2 put pop }
  235.           { pop Instances exch undef }
  236.          ifelse
  237.        }
  238.        { pop
  239.        }
  240.       ifelse
  241.     } bind
  242.  
  243. % We're still running in Level 1 mode, so dictionaries won't expand.
  244. % Leave room for the /Category entry.
  245. /Category null
  246.  
  247. .dicttomark
  248. /Category defineresource pop
  249.  
  250. % Fill in the rest of the Category category.
  251. /Category /Category findresource dup
  252. /Generic /Category findresource begin
  253.  { /FindResource /ResourceStatus /ResourceForAll }
  254.  { dup load put dup } forall
  255. pop pop end
  256.  
  257. % Define the fixed categories.
  258.  
  259. mark
  260.     % Things other than types
  261.  /ColorSpaceFamily
  262.    {/CIEBaseA /CIEBasedABC /DeviceCMYK /DeviceGray /DeviceRGB
  263.     /Indexed /Separation        % no Pattern yet
  264.    }
  265.  /Emulator
  266.    {}
  267.  /Filter
  268.    [ systemdict
  269.      { pop =string cvs (.filter_) anchorsearch
  270.         { pop cvn }
  271.         { pop }
  272.        ifelse
  273.      }
  274.     forall
  275.    ]
  276.  /IODevice
  277.    {(%os%)}
  278.     % Types
  279.  /ColorRenderingType
  280.    {1}
  281.  /FMapType
  282.    {2 3 4 5 6 7 8}
  283.  /FontType
  284.    [/.buildfont0 where {pop 0} if 1 3]
  285.  /FormType
  286.    {1}
  287.  /HalftoneType
  288.    {}
  289.  /ImageType
  290.    {1}
  291.  /PatternType
  292.    {}
  293. counttomark 2 idiv
  294.  { 7 dict begin        % 5 procedures, Category, Instances
  295.    /DefineResource
  296.     { /invalidaccess signalerror } bind def
  297.    /FindResource
  298.     { Instances exch get } bind def
  299.    /ResourceForAll
  300.     /Generic /Category findresource /ResourceForAll get def
  301.    /ResourceStatus
  302.     { Instances exch known { 0 0 true } { false } ifelse } bind def
  303.    /UndefineResource
  304.     { /invalidaccess signalerror } bind def
  305.    dup length dict dup begin exch { dup def } forall end readonly
  306.    /Instances exch def
  307.    currentdict end /Category defineresource pop
  308.  } repeat pop
  309.  
  310. % Define the other built-in categories.
  311.  
  312. mark
  313.   /ColorRendering /dicttype /ColorSpace /arraytype /Encoding /arraytype
  314.   /Font /dicttype /Form /dicttype /Halftone /dicttype /Pattern /dicttype
  315.   /ProcSet /dicttype
  316. counttomark 2 idiv
  317.  { /Generic /Category findresource dup maxlength 1 add dict copy begin
  318.    /InstanceType exch def
  319.    /Instances 10 dict def
  320.    currentdict end /Category defineresource pop
  321.  } repeat pop
  322.  
  323. % Complete the Encoding category.
  324.  
  325. /findencoding
  326.     { /Encoding findresource } odef
  327.  
  328. /Encoding /Category findresource begin
  329. % Handle lazily loaded encodings specially.
  330. Instances /SymbolEncoding [null 2 -1] put
  331. Instances /DingbatsEncoding [null 2 -1] put
  332. /.ResourceFileDict
  333.     mark
  334.       /SymbolEncoding (gs_sym_e.ps)
  335.       /DingbatsEncoding (gs_dbt_e.ps)
  336.     .dicttomark def
  337. end
  338.  
  339. /ISOLatin1Encoding ISOLatin1Encoding /Encoding defineresource pop
  340. /StandardEncoding StandardEncoding /Encoding defineresource pop
  341. /SymbolEncoding { /SymbolEncoding findencoding } bind def
  342. /DingbatsEncoding { /DingbatsEncoding findencoding } bind def
  343.  
  344. (%END of level2dict) .skipeof    %****************
  345.  
  346. % Complete the Font category.
  347.  
  348. /Font /Category findresource begin
  349. currentdict /..definefont /definefont load .growput
  350. currentdict /..findfont /findfont load .growput
  351. /DefineResource
  352.     { 2 copy ..definefont exch pop
  353.       dup [exch 0 -1] exch
  354.       Instances 4 2 roll .growput
  355.     } bind def
  356. /.LoadResource
  357.     { ..findfont pop
  358.     } bind def
  359. end
  360. % Make entries for all known fonts.
  361. /.resourceFromFontmap
  362.  { /Font /Category findresource begin
  363.    Fontmap
  364.     { pop dup Instances exch known
  365.        { pop }
  366.        { [null 2 -1] Instances 3 1 roll .growput }
  367.       ifelse
  368.     }
  369.    forall
  370.    end
  371.  } bind def
  372. .resourceFromFontmap
  373. /Font /Category findresource begin
  374. FontDirectory
  375.  { Instances 3 1 roll [exch 0 -1] .growput
  376.  }
  377. forall end
  378. /..loadFontmap /.loadFontmap load def
  379. /.loadFontmap { ..loadFontmap .resourceFromFontmap } def
  380.  
  381. /definefont
  382.     { /Font defineresource } bind def
  383. /findfont
  384.     { /Font findresource } bind def
  385. /undefinefont
  386.     { /Font undefineresource } bind def
  387.  
  388. %END of level2dict
  389.  
  390. end
  391.